class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        vector<vector<int>> vv;
        size_t i = 0;
        while (i < nums.size()) {
            size_t left = i + 1, right = nums.size() - 1;
            if(nums[i]>0)break;
           while(left<right)
           {
             if (nums[left] + nums[right] > (-1 * nums[i])) {
                right--;
            } else if (nums[left] + nums[right] < (-1 * nums[i])) {
                left++;
            } else {
                vv.push_back({nums[i], nums[left], nums[right]});
                right--;
                left++;
                while (left < right && nums[right] == nums[right + 1]) {
                    right--;
                }
                while (left < right && nums[left] == nums[left- 1]) {
                    left++;
                }
            }
           }
            i++;
            while (i < nums.size() && nums[i] == nums[i - 1])
                i++;
        }
        return vv;
    }
};